<?php require_once(dirname(__FILE__) . '/inc/config.inc.php');
IsModelPriv('goodsorder');
require_once "function.php";
$id = htmlspecialchars($id);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>任务详情</title>
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="templates/js/jquery.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="ui/css/bootstrap.min.css">
    <link rel="stylesheet" href="ui/css/bootstrap-theme.min.css">
    <link href="layui/css/layui.css" rel="stylesheet" type="text/css" media="all"/>
    <script src="layui/layui.js"></script>
    <script language="javascript" type="text/javascript" src="DatePicker/WdatePicker.js"></script>


</head>
<style>
    .layer-photos-demo img { margin-right: 10px; width: 160px; height: 160px;}

    .layui-form-label {
        float: left;
        display: block;
        padding: 9px 15px;
        width: 120px;
        font-weight: 400;
        line-height: 20px;
        text-align: right;
    }

    .gallery a {margin: 0 10px 10px 0;}

    .layui-quote-nm {
        border-left: 5px solid #666;
        border-radius: 0 2px 2px 0;
        border: 1px solid #e8b5b3;
        background: #fae2e1;
        color: #1d6d09d1;
    }

    .layui-elem-quote { padding: 0}

    .layui-quote-nm p {
        font-size: 14px;
    }
</style>
<body style="width:890px;">
<?php

$sql = "SELECT f.*,t.classname as typename,j.dataname as jinduname,d.title as devicename,f.op_manageid as op_manangid FROM `#@__order` as f
		left join `#@__tasktype`  as t on t.id=f.apply_type  
		left join `#@__task`  as d on d.id=f.apply_device
		left join `#@__cascadedata`  as j on j.datavalue=f.jindu  
		WHERE  j.datagroup='jindu'  AND   f.is_delete='0' and   f.id='$id' ";


$row = $dosql->GetOne($sql);

$odernum = date("Ymd", $row['post_time']) . "-" . $row['id'];
$order_id = $row['id'];
//故障图片

$pic_lists = "";
if ($row['picfiles'] != "") {
    $picurl_arr = json_decode($row['picfiles'], true);
    for ($i = 0; $i < count($picurl_arr); $i++) {
        $pic_lists .= '<img class="example" layer-src="' .  $picurl_arr[$i] . '" src="' .$picurl_arr[$i] . '" alt="报修图片">';
    }
}

//完修图片
$over_picurl_arr = explode(',', $row['over_picurls']);
$over_pic_lists = "";
array_pop($over_picurl_arr);
for ($i = 0; $i < count($over_picurl_arr); $i++) {
    $over_pic_lists .= '<li class="example" layer-src="' . $over_picurl_arr[$i] . '" src="' . $over_picurl_arr[$i] . '" alt="图片名"></li>';
}

//进度
$jindu = intval($row['jindu']);

//位置信息
$address_lat = $row['latitude'];
$address_long = $row['longitude'];
if ($row['apply_address'] == "" && empty($row['poster'])) {
    $must_conv = "yes";
} else {
    $must_conv = "no";

}


//类型
$tasktype = $row['apply_type'];
$task = $row['apply_device'];

$order_school = $row['school'];

//是否停止 语音
$is_accept = $row['is_accept'];

$qiang_str = "";
if ($row['mode'] == 'q') {
    $qiang_str = '<span class="label label-success">抢单</span>';
}
if ($row['mode'] == 'p') {
    $qiang_str = '<span class="label label-danger">派单</span>';
}
if ($row['mode'] == 'z') {
    $qiang_str = '<span class="label label-danger">自处理</span>';
}
?>
<div class="layui-fluid">
    <div class="layui-card">
        <h1 class="tit" style="height: 50px; line-height: 50px;">任务详情</h1>
        <div class="order_top">
            <div class="order_top1">单号：<?php echo $odernum; ?></div>
            <div class="order_top1 t_fr">
                创建日期：<?php echo date("Y年m月d日", $row['post_time']); ?> <?php if ($row['op_manangid']>0) {
                    echo "<b class='red'> 发布人：" . getManage($row['op_manangid']) . "</b>";
                } ?> </div>
        </div>
        <table width="200" border="1" class="table table-bordered">
            <tr>
                <td width="100">单位：</td>
                <td><?php echo $row['school']; ?></td>
                <td width="100">联系人：</td>
                <td><?php echo $row['truename'] . "    " . $row['mobile']; ?> </td>
            </tr>
            <tr>
                <td>地址：</td>
                <td> <?php echo $row['address'] ?></td>
                <td>位置信息：</td>
                <td id="apply_address_info"><?php if (empty($row['poster'])) {
                        echo $row['apply_address'] . "<br/>位置描述：" . $row['apply_address_name'];
                    } else {
                        echo "商务直接派单，不显示位置信息";
                    } ?></td>
            </tr>
            <tr>
                <td>服务类型</td>
                <td><?php echo $qiang_str . "  " . $row['typename']; ?></td>
                <td>设备类型：</td>
                <td><?php echo $row['devicename'] ?>
                    <?php
                    if (!empty($row['device_num'])) {
                        echo "<b class='red'>序列号：" . $row['device_num'] . "</b>";
                        $sn_num = $row['device_num'];
                        $row_sn = $dosql->GetOne("SELECT * FROM `#@__sn` WHERE `sn`='$sn_num' ");
                        if (is_array($row_sn) && isset($row_sn['id'])) {
                            // 过期时间
                            $guoqi = $row_sn['end_time'] + 86400;
                            if (time() > $guoqi) {
                                echo '<span class="label label-danger mr-5">过保</span>';
                            }
                        }
                    }
                    ?>
                </td>
            </tr>
            <tr class="red">
                <td>执行人：</td>
                <td colspan="3">
                    <?php
                    if (!empty($row['manageid'])) {
                        $m_str = $row['manageid'];
                        $m_arr = explode(",", $m_str);
                        foreach ($m_arr as $key => $val) {
                            echo ' <i class="glyphicon glyphicon-user"></i>      ' . getManage($val);
                        }
                    }
                    ?>
                </td>
            </tr>
            <?php if ($jindu > 2) { ?>
                <tr class="">
                    <td>任务时间：</td>
                    <td colspan="3"><i
                                class="glyphicon glyphicon-off green"></i> <?php echo date("Y-m-d H:i:s", $row['begintime']) . "  <i  class=' red glyphicon glyphicon-random'></i>        " . date("Y-m-d H:i:s", $row['endtime']) ?>
                    </td>
                </tr>

            <?php } ?>
            <tr>
                <td>任务详情：</td>
                <td colspan="3"><?php echo $row['content'] ?></td>
            </tr>
            <tr>
                <td>故障图片：</td>
                <td colspan="3">
                    <div id="layer-photos-demo" class="layer-photos-demo"><?php echo $pic_lists ?></div>
                </td>
            </tr>
            <tr>
                <td>任务进度：</td>
                <td colspan="3">
                    <ul class="layui-timeline">
                        <?php
                        $dosql->Execute("SELECT * FROM `#@__order_log` WHERE orderid='$id'  ORDER BY id asc");
                        while ($row2 = $dosql->GetArray()) {

                        ?>
                        <li class="layui-timeline-item">
                            <i class="layui-icon layui-timeline-axis">&#xe61a;</i>
                            <div class="layui-timeline-content layui-text">
                                <h3 class="layui-timeline-title"><?php echo $row2['op'] ?> </h3>
                                <h4 class="layui-timeline-title" style="color:#FF5722">
                                    <i class="layui-icon layui-icon-date"></i> <?php echo date("Y-m-d H:i:s", $row2['op_time']) ?>
                                </h4>
                                <?php if ($row2['remark'] != "") { ?>
                                    <blockquote class="layui-elem-quote layui-quote-nm">
                                        <p style="margin:8px;"><?php echo $row2['remark']; ?></p></blockquote>
                                <?php } ?>
                                <p>
                                    服务工程师：
                                    <?php
                                    if ($row2['manageid'] != "") {
                                        $m_str = $row2['manageid'];
                                        $m_arr = explode(",", $m_str);
                                        foreach ($m_arr as $key => $val) {
                                            echo ' <i class="glyphicon glyphicon-user"></i>      ' . getManage($val);
                                        }
                                    }
                                    ?>
                                </p>
                                <?php if ($row2['picurls'] != "") {

                                    echo '<div  class="gallery">';
                                    $picurl_arr_log = json_decode($row2['picurls'], true);

                                    foreach ($picurl_arr_log as $key => $val) {
                                        echo '<a href="javascript:;" onclick="showBigPhoto(\'order\',' . $row2['id'] . ',' . $key . ')"><img width="160px" height="160px" class="layui-upload-img" src="' . $val . '" ></a>';
                                    }
                                    echo "</div>";
                                } ?>
                                <?php if ($row2['address'] != "") {
                                    echo '<i class="layui-icon layui-icon-location red"></i> 地点：' . $row2['address'] . '   <i class="layui-icon layui-icon-location green"></i>地点描述' . $row2['address_name'];
                                } ?>
                            </div>

                            <?php }
                            ?>
                    </ul>

                </td>
            </tr>

            <?php
            if ($jindu > 1 && $row['remark']> 0) {
                ?>
                <tr>
                    <td>客服联系备注：</td>
                    <td colspan="3"><?php echo $row['remark'] ?>
                        <br/>操作时间：<?php echo date("Y-m-d H:i:s", $row['remark_time']) ?>
                    </td>
                </tr>
            <?php } ?>


            <?php
            if ($jindu > '4') {
                ?>

                <tr>
                    <td>维修概要：</td>
                    <td colspan="3"><?php echo $row['over_remark'] ?>
                        <br/>操作时间：<?php echo date("Y-m-d H:i:s", $row['over_time']) ?><br/>
                        <?php
                        $row_over = $dosql->GetOne("SELECT * FROM `#@__order_log` WHERE `orderid`='$order_id'  and wanxiu='true' ");
                        if (is_array($row_over) && isset($row_over['id'])) {
                            echo $row_over['address'] . "     位置描述：" . $row_over['address_name'];
                        }

                        ?>
                    </td>
                </tr>
                <tr>
                    <td>完修图片<? echo $jindu ?>：</td>
                    <td colspan="3">
                        <ul class="photo_list"><?php echo $over_pic_lists ?></ul>
                    </td>
                </tr>
            <?php }
            if ($jindu == 6) {
                // 评价
                $pingjia_start = "";
                $pingjia_remark = "";
                $start_str = "";
                if ($jindu == 6) {
                    $p = $dosql->GetOne("SELECT * FROM `#@__order_evaluate` WHERE orderid='$id' ");
                    if (is_array($p) && isset($p['id'])) {
                        $pingjia_start = $p['start'];
                        $pingjia_remark = $p['remark'];
                        for ($i = 0; $i < $pingjia_start; $i++) {
                            $start_str .= '<img src="img/x2.png">';
                        }
                    }
                }
                ?>
                <tr>
                    <td>服务评价星级：</td>
                    <td colspan="3"><?php echo $start_str ?></td>
                </tr>
                <tr>
                    <td>服务评价内容：</td>
                    <td colspan="3">
                        <div style=" width:650px;"><?php echo $pingjia_remark ?></div>
                    </td>
                </tr>
                <?php
            }
            ?>
        </table>
        <?php
        if ($jindu == 0) {
            echo "任务已经中止";

        }

        if ($jindu < 2 && $jindu != 0) {
            ?>
            <div class="lianxi_box">
                联系备注：
                <textarea name="remark" id="remark" class="form-control w500"></textarea>
                <button type="button" class="btn btn-danger" onclick="lianxi('<?php echo $id; ?>')">已经联系客户</button>
            </div>
            <?php
        }
        if ($jindu == 2) {
            ?>
            <div class="paidan_box">
                <table border="1" class="table table-bordered">
                    <tr height="60">
                        <td>开始时间：</td>
                        <td><input class="Wdate" name="beginTime" id="beginTime" type="text"
                                   onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                   value="<?php echo date("Y-m-d H:i:s", time()) ?>"> 结束时间：
                            <input class="Wdate" type="text"
                                   name="endTime" id="endTime"
                                   onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                   value="<?php echo date("Y-m-d H:i:s", time() + 14400) ?>">
                        </td>
                    </tr>
                    <tr>
                        <td width="100" height="50">任务类型：</td>
                        <td>
                            <div class="layui-form layui-col-md12" lay-filter="component-form-group" id="form1">
                                <div class="layui-form-item">
                                    <div class="layui-col-sm6"><label class="layui-form-label layui-bg-blue">服务类型<span
                                                    class="red">*</span></label>
                                        <div id="ordertypebox1" class="layui-input-inline">
                                            <select name="task_type" id="task_type" lay-filter="task_type">
                                                <option value="0">请选择</option>
                                                <?php

                                                $dosql->Execute("SELECT * FROM `#@__tasktype` WHERE `checkinfo`='1' and is_delete=0 order by orderid ASC", 10);
                                                while ($row_task_type = $dosql->GetArray(10)) {

                                                    $sec = "";
                                                    if ($tasktype == $row_task_type['id']) {
                                                        $sec = "selected";
                                                    }
                                                    echo '<option ' . $sec . ' value="' . $row_task_type['id'] . '" >' . $row_task_type['classname'] . '</option>';

                                                }

                                                ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-col-sm6"><label class="layui-form-label layui-bg-green">项目名称<span
                                                    class="red">*</span></label>
                                        <div id="ordertypebox1" class="layui-input-inline">
                                            <select name="task" id="task" lay-filter="task">

                                                <?php
                                                if ($task != 0) {
                                                    $dosql->Execute("SELECT * FROM `#@__task` WHERE `checkinfo`='1' and is_delete=0 and classid='$tasktype' order by orderid ASC", 10);
                                                    while ($row_task = $dosql->GetArray(10)) {
                                                        $sec = "";
                                                        if ($task == $row_task['id']) {
                                                            $sec = "selected";
                                                        }
                                                        echo '<option ' . $sec . ' value="' . $row_task['id'] . '" >' . $row_task['title'] . '</option>';

                                                    }
                                                } else {
                                                    echo '<option value="0">请选择</option>';
                                                }

                                                ?>

                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td width="100">工程师：</td>
                        <td>
                            <div class="alert alert-success" role="alert">
                                公司本部：<br/>
                                <?php
                                $dosql->Execute("SELECT * FROM  `#@__user`    WHERE  level='3'   ORDER BY id asc");
                                while ($row3 = $dosql->GetArray()) {
                                    echo '<label class="checkbox-inline"><input  type="checkbox" name="manageid" id="inlineCheckbox1" value="' . $row3['id'] . '" >' . $row3['school'] . "-" . $row3['truename'] . '</label>';

                                }


                                ?>
                            </div>

                            <div class="alert alert-danger" role="alert">
                                授权服务站：<br/>
                                <?php
                                $dosql->Execute("SELECT * FROM  `#@__user`    WHERE  level='4'   ORDER BY id asc");
                                while ($row3 = $dosql->GetArray()) {
                                    echo '<label class="checkbox-inline"><input  type="checkbox" name="manageid" id="inlineCheckbox1" value="' . $row3['id'] . '" >' . $row3['school'] . "-" . $row3['truename'] . '</label>';

                                }


                                ?>
                            </div>
                        </td>
                    </tr>
                    <tr height="80">
                        <td></td>
                        <td>
                            <button type="button" class="btn btn-danger" onclick="paidan('<?php echo $id; ?>','pai')">
                                立即派单
                            </button>
                        </td>
                    </tr>

            </div>
        <?php } ?>

        <?php
        //改派任务执行人
        if ($jindu == 3 && !empty($row['manageid'])) {
            ?>
            <div class="paidan_box">
                <table border="1" class="table table-bordered">
                    <tr height="60">
                        <td width="100">开始时间：</td>
                        <td><input class="Wdate" name="beginTime" id="beginTime" type="text"
                                   onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                   value="<?php echo date("Y-m-d H:i:s", $row['begintime']) ?>"> 结束时间：
                            <input class="Wdate"
                                   type="text"
                                   name="endTime"
                                   id="endTime"
                                   onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                   value="<?php echo date("Y-m-d H:i:s", $row['endtime']) ?>">
                        </td>
                    </tr>
                    <tr>
                        <td>工程师：</td>
                        <td>
                            <div class="alert alert-success" role="alert">
                                公司本部：<br/>
                                <?php
                                $m_ids = explode(",", $row['manageid']);
                                $dosql->Execute("SELECT * FROM  `#@__user`   WHERE level='3'  ORDER BY id asc");
                                while ($row3 = $dosql->GetArray()) {
                                    if (in_array($row3['id'], $m_ids)) {
                                        $chd = ' checked="true" ';
                                    } else {
                                        $chd = "";
                                    }
                                    echo '<label class="checkbox-inline"><input  type="checkbox" ' . $chd . ' name="manageid" id="inlineCheckbox1" value="' . $row3['id'] . '" >' . $row3['truename'] . '</label>';

                                }


                                ?>
                            </div>
                            <div class="alert alert-info" role="alert">
                                授权服务站：<br/>
                                <?php
                                $m_ids = explode(",", $row['manageid']);
                                $dosql->Execute("SELECT * FROM  `#@__user`   WHERE level='4'  ORDER BY id asc");
                                while ($row3 = $dosql->GetArray()) {
                                    if (in_array($row3['id'], $m_ids)) {
                                        $chd = ' checked="true" ';
                                    } else {
                                        $chd = "";
                                    }
                                    echo '<label class="checkbox-inline"><input  type="checkbox" ' . $chd . ' name="manageid" id="inlineCheckbox1" value="' . $row3['id'] . '" >' . $row3['truename'] . '</label>';

                                }


                                ?>
                            </div>
                        </td>

                    <tr>
                        <td>改派原因：</td>
                        <td>
                            <textarea name="remark" id="remark" class="form-control w500"></textarea>
                            <input type="hidden" name="repairid" id="repairid" value="<?php echo $row['repairid'] ?>"/>
                        </td>
                    </tr>
                    </tr>
                    <tr height="80">
                        <td></td>
                        <td>
                            <button type="button" class="btn btn-danger"
                                    onclick="paidan('<?php echo $id; ?>','gai');return false;">改派任务
                            </button>
                        </td>
                    </tr>

            </div>

        <?php } ?>


    </div>

</div>

<script>
    layui.use(['form', 'laydate', 'table', 'layedit', 'upload'], function () {
        var $ = layui.$,
            element = layui.element,
            layer = layui.layer,
            view = layui.view,
            table = layui.table,
            laytpl = layui.laytpl,
            laydate = layui.laydate,
            layedit = layui.layedit,
            upload = layui.upload,
            form = layui.form;
        //调用示例
        layer.photos({
            photos: '#layer-photos-demo'
            , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        });

        window.showBigPhoto = function (type, id, index) {
            $.ajax({
                url: "getPhoto.php?id=" + id + "&type=" + type + "&index=" + index,
                data: "",
                type: "get",
                dataType: "json",
                success: function (res) {
                    if (res.msg === "ok") {
                        //登入成功的提示与跳转
                        layer.photos({
                            photos: res.data,
                            shift: 5 //0-6的选择，指定弹出图片动画类型，默认随机

                        });

                    }
                }
            });


        }


        //获取分类
        form.on('select(task_type)', function (data) {
            console.log("点击了 任务分类");
            var typeid = data.value;
            $.ajax({
                type: 'post',
                url: "json/task/getTypeSub.php?typeid=" + typeid,
                //data: {areaId:areaId},
                dataType: 'json',
                success: function (res) {
                    console.log(res.data);
                    $("#task").html("");
                    $("#task").html(res.data);
                    form.render('select');
                    $("#task").get(0).selectedIndex = 0;
                }

            });
        });

    });

    $(function () {
        var id =<?php echo $id;?>;
        var is_accept =<?php echo $is_accept;?>;
        if (is_accept == 0) {
            var del_str = "您确定已经知晓  <?php echo $order_school;?> 的工单吗, 确认后语音不再播报?";
            layer.confirm(del_str, {
                title: '收到工单，停止播报',
                btn: ['确认', '取消'] //按钮
            }, function () {
                //操作
                $.ajax({
                    type: 'POST',
                    url: "op.php",
                    data: {id: id, op: 'is_accept'},
                    dataType: 'JSON',
                    success: function (result) {
                        console.log(result);
                        if (result.errno == 0) {
                            console.log(result.msg);
                            if (result.msg === "ok") {
                                layer.msg('操作成功');
                                window.location.reload();
                            } else {
                                layer.msg(result.err_msg);
                            }
                        }
                    }
                });
            }, function () {
                //取消操作
            });
        }
    });

    function lianxi(id) {
        var _remark = $("#remark").val();
        $.ajax({
            type: 'POST',
            url: "op.php",
            data: {id: id, op: 'lianxi', remark: _remark},
            dataType: 'JSON',
            success: function (result) {
                if (result.code === 0) {
                    $(".lianxi_box").hide();
                    layer.msg('操作成功');
                    window.location.reload();

                } else {
                    layer.msg(result.msg);
                }

            }
        });

    }

    function paidan(id, type) {
        var checkids = [];
        $("input[name='manageid']:checked").each(function (i) {
            checkids[i] = $(this).val();
        });
        ids = checkids.join(",");
        var _beginTime = $("#beginTime").val();
        var _endTime = $("#endTime").val();
        var _remark = $("#remark").val();
        var _task_type = $("#task_type").val();
        var _task = $("#task").val();
        if (_task == '0') {
            layer.msg('请选择任务类型');
            return false;
        }

        $.ajax({
            type: 'POST',
            url: "op.php",
            data: {
                id: id,
                op: 'paidan',
                manageid: ids,
                type: type,
                remark: _remark,
                beginTime: _beginTime,
                endTime: _endTime,
                task_type: _task_type,
                task: _task
            },
            dataType: 'JSON',
            success: function (result) {
                if (result.code === 0) {
                    $(".paidan_box").hide();
                    layer.msg('派单成功');
                    window.location.reload();

                } else {
                    layer.msg(result.msg);
                }
            }

        });

    }


</script>

</body>
</html>
